import { configureStore } from '@reduxjs/toolkit';


// 通知 reducer
const initialState = {
    notifications: [
        {
            id: 1,
            title: '系统通知',
            content: 'Racing car sprays burning fuel into crowd.',
            avatar: 'U',
            isRead: false
        },
        {
            id: 2,
            title: '重要公告',
            content: 'Japanese princess to wed commoner.',
            avatar: 'A',
            isRead: false
        },
        {
            id: 3,
            title: '更新提醒',
            content: 'Australian walks 100km after outback crash.',
            avatar: 'B',
            isRead: false
        },
        {
            id: 4,
            title: '安全警告',
            content: 'Man charged over missing wedding girl.',
            avatar: 'S',
            isRead: false
        },
        {
            id: 5,
            title: '系统维护',
            content: 'Los Angeles battles huge wildfires.',
            avatar: 'M',
            isRead: false
        },
    ]
};

function noticesReducer(state = initialState, action){
    switch (action.type){
        // case '处理单个的':
        // todo

        case 'MARK_ALL_READ':
            return {
                ...state,
                notifications: state.notifications.map(notice=>({
                    ...notice,
                    isRead: true
                }))
            }
        case 'MARK_READ':
            return {
                ...state,
                notifications: state.notifications.map(notification =>
                    notification.id === action.payload
                        ? { ...notification, isRead: true }
                        : notification
                )
            };
        default:
            return state;
    }
}


const store = configureStore({
    reducer: {
        notifications: noticesReducer
    }
})

export default store;
